<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="门店名称" prop="storeName">
        <el-input v-model="queryParams.storeName" placeholder="请输入门店名称" clearable @keyup.enter="handleQuery"
          style="width: 200px" />
      </el-form-item>
      <el-form-item label="门店类别" prop="storeLb">
        <el-select v-model="queryParams.storeLb" placeholder="请选择门店类别" clearable @change="handleQuery" style="width: 200px">
          <el-option v-for="dict in dep_type_list" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="门店状态" prop="isStatus">
        <el-select v-model="queryParams.isStatus" placeholder="请选择门店状态" clearable @change="handleQuery" style="width: 200px">
          <el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" size="small" icon="Plus" @click="handleAdd" v-hasPermi="['manage:store:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" size="small" icon="Delete" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['manage:store:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" size="small" icon="Download" @click="handleExport"
          v-hasPermi="['manage:store:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5" v-if="refreshTable">
				<el-button type="info" size="small" icon="sort" @click="toggleExpandAll">展开/折叠</el-button>
			</el-col>
      <el-col :span="1.5">
				<el-button type="primary" size="small" @click="handleSwitch()" :icon="switchIcon"
					:title="'切换到' + tableSwitch">{{ tableSwitch }}</el-button>
			</el-col>
      <el-col :span="2"></el-col>
      <el-col :span="1.5">
        <el-button type="warning" size="small" round class="bg-blue5 b-none">总数量: {{ onlineStore + offlineStore }}</el-button>
			</el-col>
      <el-col :span="1.5">
        <el-button type="warning" size="small" round class="bg-green5 b-none">在线数量: {{ onlineStore }}</el-button>
			</el-col>
      <el-col :span="1.5">
        <el-button type="warning" size="small" round class="bg-red5 b-none">离线数量: {{ offlineStore }}</el-button>
			</el-col>
      <el-col :span="1.5">
        <el-button type="warning" size="small" round class="bg-yellow5 b-none">在线率: {{ onlineStore && ((onlineStore / (onlineStore + offlineStore)) * 100).toFixed(0) }}%</el-button>
			</el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!-- 树状图 -->
    <el-table border stripe v-if="refreshTable" v-loading="loading" :data="storeList" row-key="storeId"
      @row-click="(row) => { console.log(row) }" :default-expand-all="isExpandAll"
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" :selectable="selectable" />
      <el-table-column label="门店名称" prop="storeName" width="200" />
      <!-- <el-table-column label="绑定门店" prop="printerKey" width="150" /> -->
      <!-- <el-table-column label="序号" type="index" width="50" /> -->
      <el-table-column label="类别" align="center" prop="storeLb">
        <template #default="scope">
          <dict-tag :options="dep_type_list" :value="scope.row.storeLb" type="success"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="isStatus">
        <template #default="scope">
          <dict-tag :options="sys_normal_disable" :value="scope.row.isStatus" type="success"/>
        </template>
      </el-table-column>
      <el-table-column label="打印机名称" align="center" prop="printerName" width="180">
        <template #default="scope">
          <span v-if="scope.row.storeLb === '2'">
            {{scope.row.printerName?.join('')}}  
            <dict-tag v-if="scope.row.printerName" :options="manage_printer_status" :value="scope.row.printerStatus" />
            <!-- <span class="color-green5" v-if="scope.row.printerStatus === '0'">在线</span>
            <span class="color-gray" v-else>离线</span> -->
          </span>
          <span v-else class="text-blue cursor-pointer" @click="()=>{proxy.$router.push('/manage/printer' )}">打印机管理</span>
        </template>
        </el-table-column>
      <el-table-column label="产品库名称" align="center" prop="productlibraryName" width="180">
        <template #default="scope">
          <span v-if="scope.row.storeLb === '2'">{{scope.row.productlibraryName}}</span>
          <span v-else class="text-blue cursor-pointer" @click="()=>{proxy.$router.push('/manage/library' )}">产品库管理</span>
        </template>
        </el-table-column>
      <el-table-column label="预警信息" align="center" width="180">
        <template #default="scope">
          <div v-if="scope.row.storeLb === '2'">
            <div>钉钉是否开启: {{scope.row.stalePastdueDdmessagelocation ? '是' : '否'}}</div>
            <div>企微是否开启: {{scope.row.stalePastdueQwmessagelocation ? '是' : '否'}}</div>
            <div>飞书是否开启: {{scope.row.stalePastdueFsmessagelocation ? '是' : '否'}}</div>
          </div>
          <span v-else >---</span>
        </template>
        </el-table-column>
      <el-table-column label="地址" align="center" prop="address" width="130" />
      <el-table-column label="备注" align="center" prop="remark" width="100" />

      <!-- <el-table-column label="联系方式" align="center" prop="contactInformation" width="130" /> -->
      <!-- <el-table-column label="显示顺序" align="center" prop="orderNum" /> -->
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="150px" class-name="small-padding fixed-width" fixed="right">
        <template #default="scope">
          <el-link type="primary" class="el-link-spacing" icon="edit" :underline="false" @click="handleUpdate(scope.row)"
            v-hasPermi="['manage:store:edit']"
            :disabled="scope.row.storeLb === '0' || (roles.includes('headquartersAdmin') && (scope.row.storeLb === '1'))">
            <span class="table_link_text">修改</span>
          </el-link>
          <el-link type="danger" class="el-link-spacing" icon="delete" :underline="false" @click="handleDelete(scope.row)"
            v-hasPermi="['manage:store:remove']"
            :disabled="scope.row.storeLb === '0' || roles.includes('headquartersAdmin') && (scope.row.storeLb === '1')">
            <span class="table_link_text">删除</span>
          </el-link>
        </template>
      </el-table-column>
    </el-table>
    <!-- 列表形式 -->
    <el-table border stripe v-if="pageTable" v-loading="loading" :data="storeList"
      @row-click="(row) => { console.log(row) }" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" :selectable="selectable" />
			<el-table-column label="序号" type="index" width="60" align="center" />
      <el-table-column label="门店名称" prop="storeName" width="150" />
      <el-table-column label="类别" align="center" prop="storeLb">
        <template #default="scope">
          <dict-tag :options="dep_type_list" :value="scope.row.storeLb" />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="isStatus">
        <template #default="scope">
          <dict-tag :options="sys_normal_disable" :value="scope.row.isStatus" />
        </template>
      </el-table-column>
      <el-table-column label="打印机名称" align="center" prop="printerName" width="180">
        <template #default="scope">
          <span v-if="scope.row.storeLb === '2'">
            {{scope.row.printerName?.join('')}}
            <dict-tag v-if="scope.row.printerName" :options="manage_printer_status" :value="scope.row.printerStatus" />

            <!-- <span class="color-green5" v-if="scope.row.printerStatus === '0'">在线</span>
            <span class="color-gray" v-else>离线</span> -->
          </span>
          <span v-else class="text-blue cursor-pointer" @click="()=>{proxy.$router.push('/manage/printer' )}">打印机管理</span>
        </template>
        </el-table-column>
      <el-table-column label="产品库名称" align="center" prop="productlibraryName" width="180">
        <template #default="scope">
          <span v-if="scope.row.storeLb === '2'">{{scope.row.productlibraryName}}</span>
          <span v-else class="text-blue cursor-pointer" @click="()=>{proxy.$router.push('/manage/library' )}">产品库管理</span>
        </template>
        </el-table-column>
        <el-table-column label="预警信息" align="center" width="180">
        <template #default="scope">
          <div v-if="scope.row.storeLb === '2'">
            <div>钉钉是否开启: {{scope.row.stalePastdueDdmessagelocation ? '是' : '否'}}</div>
            <div>企微是否开启: {{scope.row.stalePastdueQwmessagelocation ? '是' : '否'}}</div>
            <div>飞书是否开启: {{scope.row.stalePastdueFsmessagelocation ? '是' : '否'}}</div>
          </div>
          <span v-else >---</span>
        </template>
        </el-table-column>
      <el-table-column label="地址" align="center" prop="address" width="130" />
      <el-table-column label="备注" align="center" prop="remark" width="100" />
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="150px" class-name="small-padding fixed-width" fixed="right">
        <template #default="scope">
          <el-link type="primary" class="el-link-spacing" icon="edit" :underline="false" @click="handleUpdate(scope.row)"
            v-hasPermi="['manage:store:edit']"
            :disabled="scope.row.storeLb === '0' || (roles.includes('headquartersAdmin') && (scope.row.storeLb === '1'))">
            <span class="table_link_text">修改</span>
          </el-link>
          <el-link type="danger" class="el-link-spacing" icon="delete" :underline="false" @click="handleDelete(scope.row)"
            v-hasPermi="['manage:store:remove']"
            :disabled="scope.row.storeLb === '0' || roles.includes('headquartersAdmin') && (scope.row.storeLb === '1')">
            <span class="table_link_text">删除</span>
          </el-link>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0 && pageTable" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getPage" />

    <!-- 添加或修改门店对话框 -->
    <el-dialog :title="title + depStr" v-model="open" class="dialogMedia" width="40%" append-to-body destroy-on-close draggable @close="cancel">
      <el-form ref="storeRef" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="类别" prop="storeLb">
          <el-select v-model="form.storeLb" placeholder="请选择门店类型" @change="form.printerKey = []">
            <el-option v-for="dict in dep_type_list" :key="dict.value" :label="dict.label" :value="dict.value"
              :disabled="(roles.includes('headquartersAdmin')) && (dict.label === '总部')" />
          </el-select>
        </el-form-item>

        <el-form-item label="上级门店" prop="parentId">
          <el-tree-select v-model="form.parentId" :data="storeOptions"
            :props="{ value: 'storeId', label: 'storeName', children: 'children' }" value-key="deptId"
            placeholder="选择上级门店" check-strictly filterable :render-after-expand="false" style="width: 100%" default-expand-all />
        </el-form-item>

        <el-form-item :label="`${depStr}名称`" prop="storeName">
          <el-input v-model="form.storeName" :placeholder="`请输入${depStr}名称`" />
        </el-form-item>

        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注信息" />
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入门店地址" />
        </el-form-item>
        <el-form-item :label="`${depStr}状态`">
          <el-radio-group v-model="form.isStatus">
            <el-radio :label="dict.value" v-for="dict in sys_normal_disable" :key="dict.value">{{ dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="显示顺序" prop="orderNum">
          <el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
        </el-form-item>
        <el-form-item label="联系方式" prop="contactInformation">
            <el-input v-model="form.contactInformation" placeholder="请输入门店联系方式" />
          </el-form-item>
        <!-- <el-form-item label="提醒mp3文件" prop="remindMp3">
          <el-input v-model="form.remindMp3" placeholder="请输入提醒mp3文件" />
        </el-form-item> -->

        <!-- 新增门店部分 -->
        <el-form-item label="绑定打印机" prop="printerKey" v-if="depStr !== '区域'">
          <el-select v-model="form.printerKey" filterable class="w-full" placeholder="请选择打印机" multiple
            :multiple-limit="form.storeLb === '1' ? 0 : 1">
            <!-- v-infinite-scroll="getPrint" -->
            <el-option :label="dict.printerName" v-for="dict in printerList" :disabled="disPinter(dict)"
              :value="dict.printerKey" :key="dict.printerKey" />
          </el-select>
        </el-form-item>
        <template v-if="form.storeLb === '1'">
          <el-form-item label="总部logo">
            <image-upload @imageTouch="(e: any) => { form.logoPic = e }" :imageUrl="form.logoPic" />
          </el-form-item>
          
        </template>
        
        
        <el-form-item label="绑定产品库" prop="productlibraryId" v-if="form.storeLb !== '1'">
            <el-select v-model="form.productlibraryId" placeholder="请选择产品库" filterable clearable>
              <el-option v-for="library in libraryList" :value="library.id" :key="library.id"
                :label="library.productlibraryName" :disabled="library.isOpen === '1'" />
            </el-select>
          </el-form-item>
        <template v-if="form.storeLb === '2'">
          <el-form-item label="门店简称" prop="storeAbbreviation">
            <el-input v-model="form.storeAbbreviation" placeholder="请输入门店简称" />
          </el-form-item>
          <el-form-item label="门店编码" prop="storeCode">
            <el-input v-model="form.storeCode" placeholder="请输入门店编码" />
          </el-form-item>
          
          
          <el-form-item label="门店类型" prop="storeType">
            <el-select v-model="form.storeType" placeholder="请选择门店类型">
              <el-option :label="dict.label" v-for="dict in store_type_list" :value="dict.value" :key="dict.value" />
            </el-select>
          </el-form-item>
          
          <el-form-item label="营业时间" prop="businessTime">
              <el-col :span="11">
              <el-time-select v-model="form.businessTime" placeholder="营业时间" start="00:00" end="24:00" step="00:30" />
            </el-col>
            <el-col :span="2"><div class="text-center">至</div></el-col>
            <el-col :span="11">
              <el-time-select v-model="form.closeTime" placeholder="打烊时间" start="00:00" end="24:00" step="00:30" />
            </el-col>
          </el-form-item>
          <el-form-item label="钉钉机器人" prop="stalePastdueDdmessagelocation">
            <el-input v-model="form.stalePastdueDdmessagelocation" placeholder="请输入钉钉地址" />
          </el-form-item>
          <el-form-item label="飞书机器人" prop="stalePastdueFsmessagelocation">
            <el-input v-model="form.stalePastdueFsmessagelocation" placeholder="请输入飞书地址" />
          </el-form-item>
          <el-form-item label="企微机器人" prop="stalePastdueQwmessagelocation">
            <el-input v-model="form.stalePastdueQwmessagelocation" placeholder="请输入企业微信地址" />
          </el-form-item>
          <!-- <el-form-item label="门店过期日期" prop="storePastdueTime">
            <el-date-picker clearable v-model="form.storePastdueTime" type="date" value-format="YYYY-MM-DD"
              placeholder="选择门店过期日期"> </el-date-picker>
          </el-form-item> -->
          <!-- <el-form-item label="限制新增员工账号" prop="restrictAdduserCount">
            <el-input v-model="form.restrictAdduserCount" placeholder="请输入限制新增员工账号" />
          </el-form-item> -->
          <!-- <el-form-item label="生产方" prop="generateSide">
            <el-input v-model="form.generateSide" placeholder="请输入生产方" />
          </el-form-item> -->


        </template>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Store" lang="ts">
import { listStore, getStore, delStore, addStore, updateStore, listStorePage ,storeCount, easyListStore} from '@/api/system/store';
import { parseTime } from '@/utils/common';
import { getCurrentInstance, reactive, ref, watch,watchEffect,nextTick } from 'vue';
import { getPrinterAllData, getPrinterAll , addPrinters} from '@/api/manage/printer';
import useClassify from '@/api/request/manage/classify';
import useUserStore from '@/store/modules/user';
import useStore from './common/require';
import {debounce} from '@/utils';
// import router from '@/router';
const { rules } = useStore();
// import { regionData } from 'element-china-area-data';
// import user from '@/api/request/system/user';
const { libraryList } = useClassify();

const { proxy } = getCurrentInstance() as any;
const { dep_type_list,sys_normal_disable, store_type_list,manage_printer_status} = proxy.useDict('dep_type_list','sys_normal_disable','store_type_list','manage_printer_status');
const storeList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref('');
const depStr = ref(''); // 门店 ｜ 区域 ｜ 门店（根据id值变化）
const storeOptions = ref([]); //
const allStore = ref([]);
const printerList = ref<any[]>([]);// 打印机列表
const queryRef = ref();
const { roles } = useUserStore();
const form = ref<any>({});
const queryParams = ref({
	pageNum: 1,
	pageSize: 10,
	storeName: '',
	isStatus: '',
	storeLb: '',
});
const isExpandAll = ref(false);
const printParams = ref({
	pageNum: 1,
	pageSize: 10,
	query: ''
});
const defaultExpandAll = ref(true);
watch(
	() => form.value.storeLb,
	newVal => {
		const filterList = dep_type_list.value.filter((ele: { value: string }) => ele.value === newVal);
		depStr.value = filterList[0].label;
		// 是区域时，不是必选
		if(newVal === '3'){
			rules.value.productlibraryId[0].required = false;
		}else{
			rules.value.productlibraryId[0].required = true;
		}
		// 如果是总部时候，打印机不是必选
		if(newVal === '1'){
			rules.value.printerKey[0].required = false;
		}else{
			rules.value.printerKey[0].required = true;
		}
		// allStore.value.forEach((ele:any) => {
		// 	ele.disabled = false;
		// 	if( +ele.storeLb > +newVal){
		// 		ele.disabled = true;
		// 	} 
		// });
		// storeOptions.value = proxy.handleTree(allStore.value, 'storeId');
	}
);

/** 展开/折叠操作 */
const toggleExpandAll = () => {
	refreshTable.value = false;
	isExpandAll.value = !isExpandAll.value;
	nextTick(() => {
		refreshTable.value = true;
	});
};
/** 查询门店列表 */
function getList() {
	loading.value = true;
	listStore(queryParams.value).then((response: any) => {
		console.log('所有门店信息：', response);
		// storeList.value = response.data;
		storeList.value = proxy.handleTree(response.data, 'storeId');
		total.value = response.data.total || response.data.length || 0;
		loading.value = false;
	});
}
/** 分页查询门店列表 */
function getPage() {
	loading.value = true;
	console.log('fnegy',queryParams.value);
	listStorePage(queryParams.value).then((response: any) => {
		console.log('所有门店信息：', response);
		storeList.value = response.data.list;
		total.value = response.data.total || response.data.length || 0;
		loading.value = false;
	});
}

// 取消按钮
function cancel() {
	open.value = false;
	reset();
}

// 表单重置
function reset() {
	form.value = {
		storeId: '',
		parentId: '',
		ancestors: '',
		storeName: '',
		storeAbbreviation: '',
		storeCode: '',
		storeType: '1',
		storeLb: roles.includes('headquartersAdmin') ? '2' : '1',
		remark: '',
		isStatus: '0',
		businessTime: '08:30',
		closeTime: '17:30',
		storePastdueTime: '',
		remindMp3: '',
		restrictAdduserCount: '',
		generateSide: '',
		address: '',
		contactInformation: '',
		orderNum: 0,
		productlibraryId: '',
		printerKey: [],
		stalePastdueDdmessagelocation: '',
		stalePastdueFsmessagelocation: '',
		stalePastdueQwmessagelocation: ''

	};
	proxy.resetForm('storeRef');
}


/** 搜索按钮操作 */
function handleQuery() {
	queryParams.value.pageNum = 1;
	if(pageTable.value){
		getPage();
	}else{
		getList();
	}
}

/** 重置按钮操作 */
function resetQuery() {
	proxy.resetForm(queryRef);
	handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection: any) {
	ids.value = selection.map((item: any) => item.storeId);
	single.value = selection.length !== 1;
	multiple.value = !selection.length;
}
function selectable(row:any){
	return !(row.storeLb === '0' || (roles.includes('headquartersAdmin') && (row.storeLb === '1')));
}

/** 新增按钮操作 */
async function handleAdd() {
	reset();
	// const storeRes = await listStore(queryParams.value);
	// storeOptions.value = proxy.handleTree(storeRes.data, 'storeId');
	open.value = true;
	title.value = '添加';
	getStoreName();
	getPrinter();
}

/** 修改按钮操作 */
async function handleUpdate(row: any) {
	reset();
	form.value = {...row};
	open.value = true;
	title.value = '修改';
	getStoreName();
	getPrinter();
	
	// const storeId = row.storeId || ids.value;
	// getStore(storeId).then(response => {
	// 	form.value = response.data;
	// 	open.value = true;
	// 	title.value = '修改';
	// });
}

/** 提交按钮 */
function submitForm() {
	proxy.$refs['storeRef'].validate((valid: boolean) => {
		if (valid) {
			if (form.value.storeId) {
				updateStore(form.value).then(response => {
					proxy.$modal.msgSuccess('修改成功');
					open.value = false;
					if(pageTable.value){
						getPage();
					}else{
						getList();
					}
				});
			} else {
				addStore(form.value).then(response => {
					proxy.$modal.msgSuccess('新增成功');
					open.value = false;
					if(pageTable.value){
						getPage();
					}else{
						getList();
					}
				});
			}
		}
	});
}

/** 删除按钮操作 */
function handleDelete(row: any) {
	const storeIds = row.storeId || ids.value;
	proxy.$modal
		.confirm('是否确认删除门店编号为"' + storeIds + '"的数据项？')
		.then(function () {
			return delStore(storeIds);
		})
		.then(() => {
			if(pageTable.value){
				getPage();
			}else{
				getList();
			}
			proxy.$modal.msgSuccess('删除成功');
		})
		.catch(() => { });
}

/** 导出按钮操作 */
function handleExport() {
	proxy.download(
		'manage/store/exportByStream',
		{
			...queryParams.value,
		},
		`store_${new Date().getTime()}.xlsx`
	);
}

// watch(form, (newVal) => {
// 	const keyList = Object.keys(newVal);
// 	keyList.forEach(ele => {
// 		let writeList = ['id', 'remark'];
// 		if (!writeList.includes(ele)) {
// 			rules[ele] = [
// 				{ required: true, message: '', trigger: 'blur' },
// 			];
// 		}

// 	});
// });
const onlineStore = ref(0);
const offlineStore = ref(0);
async function getOther() {

	const storeOnlineRes = await storeCount();
	console.log(storeOnlineRes.data.zx);
	onlineStore.value = storeOnlineRes.data.zx;
	offlineStore.value = storeOnlineRes.data.lx || 0;

	// const printerRes: any = await getPrinterAll();
	// printerList.value = printerRes.data.list;
	
}
async function getStoreName(){
	// const storeRes = await easyListStore({storeLb:'1'});
	// const storeRes2 = await easyListStore({storeLb:'3'});
	// const res = [...storeRes.data,...storeRes2.data];
	// console.log(storeRes,'storeRes');
	// storeOptions.value = proxy.handleTree(res, 'storeId');
	const storeRes = await easyListStore({});
	storeRes.data.forEach((ele:any) => {
		if( ele.storeLb === '2'){
			ele.disabled = true;
		}
	});
	storeOptions.value = proxy.handleTree(storeRes.data, 'storeId');
}
async function getPrinter(){
	const printerRes: any = await getPrinterAll();
	printerList.value = printerRes.data.list;
}
async function getPrint(){
	// disableInfinite.value = true;
	console.log('xxx');
	// printParams.value.pageNum += num;
	const params = {...printParams.value,pageNum:printParams.value.pageNum +1};
	const printerRes: any = await getPrinterAll(params);
	// console.log('printerList:打印机列表---：', printerRes);
	printerList.value = [...printerList.value,...printerRes.data.list];
	// disableInfinite.value = false;

}
/**
 * 根据需求判断当前打印机是否禁用
 * @param pinter 打印机信息
 */
function disPinter(pinter:any){
	// 如果是总部
	if(form.value.storeLb==='1'){
		return pinter.headquartersId && !(pinter.headquartersId === form.value.storeId);
	}else if(form.value.storeLb === '2'){
		return pinter.storeId && !(pinter.storeId === form.value.storeId);
	}
}

const tableSwitch = ref<string>('树形表格');
const switchIcon = ref<string>('list');
const pageTable = ref<boolean>(true); // 按照表格形式
const refreshTable = ref<boolean>(false); // 按照树形结构

/**
	 * 切换表格数据
	 */
const switchTable = () => {
	ids.value = [];
	pageTable.value = !pageTable.value;
	refreshTable.value = !refreshTable.value;
	if (!pageTable.value && refreshTable.value) {
		total.value = 0;
		tableSwitch.value = '分页表格';
		switchIcon.value = 'list';
		getList();
	} else {
		tableSwitch.value = '树形表格';
		switchIcon.value = 'grid';
		getPage();

	}
};

// 切换表格增加防抖
const handleSwitch = debounce(switchTable, 700, true);

getPage();
getOther();
</script>
